//
//  CQExtralTagSeletedCollectionView.h
//  CJUIKitDemo
//
//  Created by ciyouzen on 2017/9/11.
//  Copyright © 2017年 dvlproad. All rights reserved.
//
//  可以选中的collectionView

#import <UIKit/UIKit.h>
#import <Masonry/Masonry.h>
#import <CJCollectionViewDataSource/CJDataSourceSettingModel.h>
#import <CJCollectionViewDataSource/CJTagSectionDataModel.h>
#import "CQTagModel.h"


NS_ASSUME_NONNULL_BEGIN

///用来测试将CollectionView包含在自定义的View中时候，时候会有错误
@interface CQExtralTagSeletedCollectionView : UICollectionView {
    
}
@property (nonatomic, strong, readonly) NSMutableArray<CJTagSectionDataModel *> *tagSectionModels;/**< 数据源 */
@property (nonatomic, strong, readonly) NSArray<NSString *> *selectedTagNames;

/*
 *  初始化标签视图
 *
 *  @param itemHorizontalSpacing    两个item之间的水平间距
 *  @param itemVerticalSpacing      两个item之间的竖直间距
 *  @param sectionLeftRightInset    每个section左右离边缘的间距
 *  @param sectionSpacing           两个section之间的间距
 *  @param sectionSettingBlock      根据需要设置每个section。（当某个section的这个block①为nil时,该区个数无限制且无额外item,即显示实际个数；②为非nil时,该区个数可限制且可设置个数未超限时,额外item的位置(当有个数限制且超过后，+号会隐藏)）
 *  @param textFormatBlock          将text格式化的方法（比如传入省市，但我们只想显示市），默认nil，表示使用原值显示
 *  @param addTagBlock              添加tag的方法
 *  @param updateTagBlock           更新所添加的tag的文本方法
 *
 *  @return 标签视图
 */
- (instancetype)initWithItemHorizontalSpacing:(CGFloat)itemHorizontalSpacing
                          itemVerticalSpacing:(CGFloat)itemVerticalSpacing
                        sectionLeftRightInset:(CGFloat)sectionLeftRightInset
                               sectionSpacing:(CGFloat)sectionSpacing
                          sectionSettingBlock:(CJDataSourceSettingModel* (^ _Nullable)(NSInteger section))sectionSettingBlock
                              textFormatBlock:(NSString *(^ _Nullable)(NSString *originText))textFormatBlock
                                  addTagBlock:(void(^)(CQExtralTagSeletedCollectionView *bCollectionView, NSIndexPath *indexPath))addTagBlock
                               updateTagBlock:(void(^)(CQExtralTagSeletedCollectionView *bCollectionView, NSIndexPath *indexPath, NSString *oldTagString))updateTagBlock NS_DESIGNATED_INITIALIZER;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;

/*
 *  设置回调
 *
 *  @param tagChangeBlock           tag内容改变的回调(会同时触发selectedTagChangeBlock。indexPath：在哪个位置新增，或者在哪个位置修改)
 *  @param selectedTagChangeBlock   选中的tag改变的回调
 */
- (void)setupTagChangeBlock:(void(^ _Nullable)(NSMutableArray<CJTagSectionDataModel *> *tagSectionModels, NSIndexPath *indexPath))tagChangeBlock
     selectedTagChangeBlock:(void(^ _Nonnull)(NSArray<NSString *> *tagNames))selectedTagChangeBlock;

/*
 *  设置不能编辑的标签和默认选中的标签(会自动调用reloadData)
 *
 *  @param unableEditTagSectionStrings  设置不能编辑的标签
 *  @param defaultSelectTagString       默认选中的标签
 */
- (void)configUnableEditTagSectionStrings:(NSArray<NSArray<NSString *> *> *)unableEditTagSectionStrings
                   defaultSelectTagString:(nullable NSString *)defaultSelectTagString;

#pragma mark - Update
/*
 *  更新section的设置
 *
 *  @param sectionSettingBlock                  集合视图的每个section的设置(可为nil，为nil表示无个数限制，且无额外item)
 */
- (void)updateSectionSettingBlock:(CJDataSourceSettingModel* (^ _Nullable)(NSInteger section))sectionSettingBlock;

#pragma mark - Event
/// 添加标签及其内容
- (void)addTagString:(NSString *)tagString indexPath:(NSIndexPath *)indexPath;
/// 更新标签内容
- (void)updateTagString:(NSString *)tagString indexPath:(NSIndexPath *)indexPath;

@end

NS_ASSUME_NONNULL_END
